package com.example.wm.producer;

import com.example.wm.constants.KafkaConstants;
import com.example.wm.models.Container;
import com.example.wm.models.WarehouseEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/produce")
public class WarehouseEntryProducer {

    /*
 *
 * {
	  "warehouseEntryNumber": "WH-IN-20230719-001",
	  "entryDate": "2023-07-19",
	  "supplier": "SupplierName",
	  "totalContainers": 2,
	  "containers": [
	    {
	      "containerNumber": "CNTR-123456",
	      "containerType": "20 feet",
	      "goodsDescription": "Electronic products",
	      "quantity": 100,
	      "storageLocation": "Area A - Row 1 - Position 5",
	      "expectedOutboundDate": "2023-08-10"
	    },
	    {
	      "containerNumber": "CNTR-789012",
	      "containerType": "40 feet",
	      "goodsDescription": "Machinery and equipment",
	      "quantity": 50,
	      "storageLocation": "Area B - Row 2 - Position 3",
	      "expectedOutboundDate": "2023-08-20"
	    }
	  ],
	  "remarks": "Please ensure the goods are stored within 24 hours and verify the container numbers and quantities.",
	  "operator": "OperatorName",
	  "auditor": "AuditorName"
	}
 */
    @Autowired
    private KafkaTemplate<String, WarehouseEntry> kafkaTemplate;

    @PostMapping("/message")
    public String sendMessage(@RequestBody WarehouseEntry message) {


        try {
            kafkaTemplate.send(KafkaConstants.WS_ENTRY_TOPIC, message);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "Send warehouseEntry message successfully";
    }

}
